Micron Document
NexusPi Git Node


Displaying Raw • Download

lib/microReticulum/src/Utilities/Stream.h copilot/add-rtnode-configuration-options (9529fa8a) Text, 5.48 KB

T8b949e/*
Stream.h - base class for character-based streams.
Copyright (c) 2010 David A. Mellis. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

parsing functions based on TextFinder library by Michael Margolis
*/

Tff7b72#Tff7b72ifndef ARDUINO

Tff7b72#Tff7b72ifndef Stream_h
Tff7b72#Tff7b72define Stream_h

Tff7b72#Tff7b72include T8b949e<inttypes.h>
Tff7b72#Tff7b72include T8b949e"Print.h"

T8b949e// compatability macros for testing
T8b949e/*
#define getInt() parseInt()
#define getInt(skipChar) parseInt(skipchar)
#define getFloat() parseFloat()
#define getFloat(skipChar) parseFloat(skipChar)
#define getString( pre_string, post_string, buffer, length)
readBytesBetween( pre_string, terminator, buffer, length)
*/

Te6edf3class Te6edf3StreamTff7b72: Te6edf3public Te6edf3Print
Tb4b4b4{
Te6edf3protectedTff7b72:
Tffa657unsigned Tffa657long Te6edf3_timeoutTb4b4b4; T8b949e// number of milliseconds to wait for the next char before aborting timed read
Tffa657unsigned Tffa657long Te6edf3_startMillisTb4b4b4; T8b949e// used for timeout measurement
Tffa657int Td2a8fftimedReadTb4b4b4(Tb4b4b4)Tb4b4b4; T8b949e// private method to read stream with timeout
Tffa657int Td2a8fftimedPeekTb4b4b4(Tb4b4b4)Tb4b4b4; T8b949e// private method to peek stream with timeout
Tffa657int Td2a8ffpeekNextDigitTb4b4b4(Tb4b4b4)Tb4b4b4; T8b949e// returns the next numeric digit in the stream or -1 if timeout

Te6edf3publicTff7b72:
Te6edf3virtual Tffa657int Te6edf3availableTb4b4b4(Tb4b4b4) Tff7b72= T79c0ff0Tb4b4b4;
Te6edf3virtual Tffa657int Te6edf3readTb4b4b4(Tb4b4b4) Tff7b72= T79c0ff0Tb4b4b4;
Te6edf3virtual Tffa657int Te6edf3peekTb4b4b4(Tb4b4b4) Tff7b72= T79c0ff0Tb4b4b4;

Te6edf3StreamTb4b4b4(Tb4b4b4)Tff7b72:Te6edf3_startMillisTb4b4b4(T79c0ff0Tb4b4b4)
Tb4b4b4{
Te6edf3_timeout Tff7b72= T79c0ff1000Tb4b4b4;
Tb4b4b4}
Te6edf3virtual Tff7b72~Te6edf3StreamTb4b4b4(Tb4b4b4) Tb4b4b4{Tb4b4b4}

T8b949e// parsing methods

Tffa657void Te6edf3setTimeoutTb4b4b4(Tffa657unsigned Tffa657long Te6edf3timeoutTb4b4b4)Tb4b4b4; T8b949e// sets maximum milliseconds to wait for stream data, default is 1 second
Tffa657unsigned Tffa657long Td2a8ffgetTimeoutTb4b4b4(Tffa657voidTb4b4b4)Tb4b4b4;
Tffa657bool Td2a8fffindTb4b4b4(Tff7b72const Tffa657char Tff7b72*Te6edf3targetTb4b4b4)Tb4b4b4; T8b949e// reads data from the stream until the target string is found
Tffa657bool Td2a8fffindTb4b4b4(Tffa657uint8_t Tff7b72*Te6edf3targetTb4b4b4)
Tb4b4b4{
Tff7b72return Te6edf3findTb4b4b4(Tb4b4b4(Tffa657char Tff7b72*Tb4b4b4) Te6edf3targetTb4b4b4)Tb4b4b4;
Tb4b4b4}
T8b949e// returns true if target string is found, false if timed out (see setTimeout)

Tffa657bool Td2a8fffindTb4b4b4(Tff7b72const Tffa657char Tff7b72*Te6edf3targetTb4b4b4, Tffa657size_t Te6edf3lengthTb4b4b4)Tb4b4b4; T8b949e// reads data from the stream until the target string of given length is found
Tffa657bool Td2a8fffindTb4b4b4(Tff7b72const Tffa657uint8_t Tff7b72*Te6edf3targetTb4b4b4, Tffa657size_t Te6edf3lengthTb4b4b4)
Tb4b4b4{
Tff7b72return Te6edf3findTb4b4b4(Tb4b4b4(Tffa657char Tff7b72*Tb4b4b4) Te6edf3targetTb4b4b4, Te6edf3lengthTb4b4b4)Tb4b4b4;
Tb4b4b4}
T8b949e// returns true if target string is found, false if timed out

Tffa657bool Td2a8fffindTb4b4b4(Tffa657char Te6edf3targetTb4b4b4)
Tb4b4b4{
Tff7b72return Te6edf3find Tb4b4b4(Tff7b72&Te6edf3targetTb4b4b4, T79c0ff1Tb4b4b4)Tb4b4b4;
Tb4b4b4}

Tffa657bool Td2a8fffindUntilTb4b4b4(Tff7b72const Tffa657char Tff7b72*Te6edf3targetTb4b4b4, Tff7b72const Tffa657char Tff7b72*Te6edf3terminatorTb4b4b4)Tb4b4b4; T8b949e// as find but search ends if the terminator string is found
Tffa657bool Td2a8fffindUntilTb4b4b4(Tff7b72const Tffa657uint8_t Tff7b72*Te6edf3targetTb4b4b4, Tff7b72const Tffa657char Tff7b72*Te6edf3terminatorTb4b4b4)
Tb4b4b4{
Tff7b72return Te6edf3findUntilTb4b4b4(Tb4b4b4(Tffa657char Tff7b72*Tb4b4b4) Te6edf3targetTb4b4b4, Te6edf3terminatorTb4b4b4)Tb4b4b4;
Tb4b4b4}

Tffa657bool Td2a8fffindUntilTb4b4b4(Tff7b72const Tffa657char Tff7b72*Te6edf3targetTb4b4b4, Tffa657size_t Te6edf3targetLenTb4b4b4, Tff7b72const Tffa657char Tff7b72*Te6edf3terminateTb4b4b4, Tffa657size_t Te6edf3termLenTb4b4b4)Tb4b4b4; T8b949e// as above but search ends if the terminate string is found
Tffa657bool Td2a8fffindUntilTb4b4b4(Tff7b72const Tffa657uint8_t Tff7b72*Te6edf3targetTb4b4b4, Tffa657size_t Te6edf3targetLenTb4b4b4, Tff7b72const Tffa657char Tff7b72*Te6edf3terminateTb4b4b4, Tffa657size_t Te6edf3termLenTb4b4b4)
Tb4b4b4{
Tff7b72return Te6edf3findUntilTb4b4b4(Tb4b4b4(Tffa657char Tff7b72*Tb4b4b4) Te6edf3targetTb4b4b4, Te6edf3targetLenTb4b4b4, Te6edf3terminateTb4b4b4, Te6edf3termLenTb4b4b4)Tb4b4b4;
Tb4b4b4}

Tffa657long Td2a8ffparseIntTb4b4b4(Tb4b4b4)Tb4b4b4; T8b949e// returns the first valid (long) integer value from the current position.
T8b949e// initial characters that are not digits (or the minus sign) are skipped
T8b949e// integer is terminated by the first character that is not a digit.

Tffa657float Td2a8ffparseFloatTb4b4b4(Tb4b4b4)Tb4b4b4; T8b949e// float version of parseInt

Te6edf3virtual Tffa657size_t Te6edf3readBytesTb4b4b4(Tffa657char Tff7b72*Te6edf3bufferTb4b4b4, Tffa657size_t Te6edf3lengthTb4b4b4)Tb4b4b4; T8b949e// read chars from stream into buffer
Te6edf3virtual Tffa657size_t Te6edf3readBytesTb4b4b4(Tffa657uint8_t Tff7b72*Te6edf3bufferTb4b4b4, Tffa657size_t Te6edf3lengthTb4b4b4)
Tb4b4b4{
Tff7b72return Te6edf3readBytesTb4b4b4(Tb4b4b4(Tffa657char Tff7b72*Tb4b4b4) Te6edf3bufferTb4b4b4, Te6edf3lengthTb4b4b4)Tb4b4b4;
Tb4b4b4}
T8b949e// terminates if length characters have been read or timeout (see setTimeout)
T8b949e// returns the number of characters placed in the buffer (0 means no valid data found)

Tffa657size_t Te6edf3readBytesUntilTb4b4b4(Tffa657char Te6edf3terminatorTb4b4b4, Tffa657char Tff7b72*Te6edf3bufferTb4b4b4, Tffa657size_t Te6edf3lengthTb4b4b4)Tb4b4b4; T8b949e// as readBytes with terminator character
Tffa657size_t Td2a8ffreadBytesUntilTb4b4b4(Tffa657char Te6edf3terminatorTb4b4b4, Tffa657uint8_t Tff7b72*Te6edf3bufferTb4b4b4, Tffa657size_t Te6edf3lengthTb4b4b4)
Tb4b4b4{
Tff7b72return Te6edf3readBytesUntilTb4b4b4(Te6edf3terminatorTb4b4b4, Tb4b4b4(Tffa657char Tff7b72*Tb4b4b4) Te6edf3bufferTb4b4b4, Te6edf3lengthTb4b4b4)Tb4b4b4;
Tb4b4b4}
T8b949e// terminates if length characters have been read, timeout, or if the terminator character detected
T8b949e// returns the number of characters placed in the buffer (0 means no valid data found)

T8b949e// Arduino String functions to be added here
Te6edf3virtual Te6edf3stdTff7b72:Tff7b72:Te6edf3string Te6edf3readStringTb4b4b4(Tb4b4b4)Tb4b4b4;
Te6edf3stdTff7b72:Tff7b72:Te6edf3string Td2a8ffreadStringUntilTb4b4b4(Tffa657char Te6edf3terminatorTb4b4b4)Tb4b4b4;

Te6edf3protectedTff7b72:
Tffa657long Te6edf3parseIntTb4b4b4(Tffa657char Te6edf3skipCharTb4b4b4)Tb4b4b4; T8b949e// as above but the given skipChar is ignored
T8b949e// as above but the given skipChar is ignored
T8b949e// this allows format characters (typically commas) in values to be ignored

Tffa657float Td2a8ffparseFloatTb4b4b4(Tffa657char Te6edf3skipCharTb4b4b4)Tb4b4b4; T8b949e// as above but the given skipChar is ignored
Tff7b72struct T56d364MultiTarget Tb4b4b4{
Tff7b72const Tffa657char Tff7b72*Te6edf3strTb4b4b4; T8b949e// string you're searching for
Tffa657size_t Te6edf3lenTb4b4b4; T8b949e// length of string you're searching for
Tffa657size_t Te6edf3indexTb4b4b4; T8b949e// index used by the search routine.
Tb4b4b4}Tb4b4b4;

T8b949e// This allows you to search for an arbitrary number of strings.
T8b949e// Returns index of the target that is found first or -1 if timeout occurs.
Tffa657int Td2a8fffindMultiTb4b4b4(Tff7b72struct T56d364MultiTarget Tff7b72*Te6edf3targetsTb4b4b4, Tffa657int Te6edf3tCountTb4b4b4)Tb4b4b4;

Tb4b4b4}Tb4b4b4;

Tff7b72#Tff7b72endif

Tff7b72#Tff7b72endif

Served by rngit 1.4.2 - Generated in 0.02s